Monado Runtime源码结构分析

Monado Runtime源码结构分析

源码地址

monado的源码下载地址:https://gitlab.freedesktop.org/monado/monado

Monado source tree

ReadMe.md的部分已经有阐释了整个工程的目录概要:

  • src/xrt/include - headers that define the internal interfaces of Monado.
  • src/xrt/compositor - code for doing distortion and driving the display hardware of a device.
  • src/xrt/auxiliary - utilities and other larger components.
  • src/xrt/drivers - hardware drivers.
  • src/xrt/state_trackers/oxr - OpenXR API implementation.
  • src/xrt/targets - glue code and build logic to produce final binaries.
  • src/external - a small collection of external code and headers.

gradle for Android

参考根目录下的settings.gradle文件,可以看出整个工程其实是包含了4个部分的:

  • rootProject.name = ‘monado’
  • include ':src:xrt:auxiliary:android'
  • include ':src:xrt:ipc:android'
  • include ':src:xrt:targets:android_common'
  • include ':src:xrt:targets:openxr_android'

这个是我们非常熟悉的Android工程的结构了,根据以往的经验,我们需要从com.android.application的工程入手进行分析。

openxr_android

整个工程编译apk的主module是openxr_android,因此先分析openxr_android/build.gradle

build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
......
plugins {
id 'com.android.application'
......
}
......
android {
......
defaultConfig {
applicationId 'org.freedesktop.monado.openxr_runtime'
......
externalNativeBuild {
cmake {
arguments "-DEIGEN3_INCLUDE_DIR=${project.eigenIncludeDir}",
"-DANDROID_PLATFORM=26",
"-DANDROID_STL=c++_shared",
"-DANDROID_ARM_NEON=TRUE"
}
if (project.pythonBinary != null) {
println "Path to Python 3 explicitly specified: ${project.pythonBinary}"
cmake.arguments "-DPYTHON_EXECUTABLE=${project.pythonBinary}"
}
}
......
}
......
externalNativeBuild {
cmake {
path "${rootDir}/CMakeLists.txt"
}
}
......
flavorDimensions 'deployment'
productFlavors {
inProcess {
dimension 'deployment'
applicationIdSuffix '.in_process'
externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=OFF"
externalNativeBuild.cmake.targets "openxr_monado"
resValue "string", "app_name", "Monado XR"
}
outOfProcess {
dimension 'deployment'
applicationIdSuffix '.out_of_process'
externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=ON"
externalNativeBuild.cmake.targets "openxr_monado", "monado-service"
resValue "string", "app_name", "Monado XR (Out-of-Proc)"
}
}
......
}
......
dependencies {
outOfProcessImplementation project(':src:xrt:ipc:android')
implementation project(':src:xrt:auxiliary:android')
implementation project(':src:xrt:targets:android_common')
......
}

在这里有三个关键点:

  1. 整个工程的CMakeLists.txt"${rootDir}/CMakeLists.txt",也即monado/CMakeLists.txt

  2. 区分了productFlavors,包含了两个选项:inProcessoutOfProcess

    inProcessFlavors下,会定义XRT_FEATURE_SERVICE=OFF

    outOfProcessFlavors下,会定义XRT_FEATURE_SERVICE=ON

  3. 仅在outOfProcessFlavors下会引用到:src:xrt:ipc:android

    outOfProcessImplementation project(':src:xrt:ipc:android')

因此,如果只是编译inProcess的模式,那么就不会包含src/xrt/ipc/android目录下的相关代码了,这边以inProcess为例进行分析。

auxiliary:android

auxiliary的翻译是辅助的,这个目录的gradle中并没有包含太多的信息,也没有包含CMakeLists的部分,因此只是一个纯android工程而已。

img

其中的具体作用以后再分析。

targets:android_common

这个模块的部分跟auxiliary:android非常类似,在build.gradle中也没有CMakeLists,也是一个普通的android library模块。

img

monado

根目录下的CMakeLists文件是整个monado runtime so的起始点,文件的部分有点长,一共有将近500行,逐段分析一下。

在分析之前需要记得一点,由于我们是通过gradle进行编译的inProcess,在CMakeLists.txt之外有额外给出了一个参数:XRT_FEATURE_SERVICE=OFF

  • 最早的60行大部分内容都是在定义环境变量,诸如指定CMake版本,C++版本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    # Copyright 2018-2021, Collabora, Ltd.
    # SPDX-License-Identifier: BSL-1.0
    cmake_minimum_required(VERSION 3.10.2)
    project(XRT VERSION 21.0.0)
    # CMake 3.11 introduced CMP0072 - Prefer GLVND
    if(POLICY CMP0072)
    cmake_policy(SET CMP0072 NEW)
    endif()
    option(
    XRT_OPENXR_INSTALL_ABSOLUTE_RUNTIME_PATH
    "Use the absolute path to the runtime in the installed manifest, rather than a bare filename."
    ON
    )
    option(XRT_OPENXR_INSTALL_ACTIVE_RUNTIME "Make Monado the default OpenXR runtime on install" ON)
    # We use C++17
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    # So that clangd/Intellisense/Sourcetrail know how to parse our code.
    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    ###
    # Dependencies
    ###
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sanitizers")
    include(CMakeDependentOption)
    include(SPIR-V)
    include(GNUInstallDirs)
    if(NOT GIT_DESC)
    include(GetGitRevisionDescription)
    git_describe(GIT_DESC "--always")
    endif()
    if(NOT ${CMAKE_VERSION} VERSION_LESS 3.9)
    include(CheckIPOSupported)
    check_ipo_supported(RESULT HAS_IPO)
    endif()
    # Android SDK doesn't look for 3.8 and 3.9, which is what new distros ship with.
    set(Python_ADDITIONAL_VERSIONS 3.8 3.9)
    if(NOT CMAKE_VERSION VERSION_LESS 3.12)
    find_package(Python3 REQUIRED Interpreter)
    set(PYTHON_EXECUTABLE Python3::Interpreter)
    else()
    find_program(PYTHON_EXECUTABLE python3)
    if(PYTHON_EXECUTABLE MATCHES "WindowsApps")
    # If you hit this error, you will have to install Python 3 or try harder to tell CMake where it is.
    message(
    FATAL_ERROR
    "Found WindowsApps alias for Python. Make sure Python3 is installed, then choose 'Manage App Execution Aliases' in Start and disable the aliases for Python."
    )
    endif()
    endif()
  • 第二个部分是一些项目中会使用到的依赖库

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    find_package(Eigen3 3 REQUIRED)
    find_package(Vulkan MODULE)
    find_package(EGL MODULE)
    find_package(HIDAPI MODULE)
    find_package(OpenHMD MODULE)
    find_package(
    OpenCV
    COMPONENTS
    core
    calib3d
    highgui
    imgproc
    imgcodecs
    features2d
    video
    CONFIG
    )
    find_package(Libusb1 MODULE)
    find_package(JPEG MODULE)
    find_package(realsense2 CONFIG)
    find_package(depthai CONFIG)
    find_package(SDL2 CONFIG)
    find_package(ZLIB MODULE)
    find_package(cJSON MODULE)
    find_package(Systemd MODULE)
    find_package(OpenGLES MODULE COMPONENTS V3)
    find_package(LeapV2 MODULE)
    find_package(ONNXRuntime MODULE)
    find_package(Percetto MODULE)
    if(NOT ANDROID)
    find_package(PkgConfig MODULE)
    endif()
    #https://github.com/arsenm/sanitizers-cmake
    find_package(Sanitizers MODULE)
    add_library(xrt-pthreads INTERFACE)
    if(WIN32)
    find_package(pthreads_windows REQUIRED)
    target_link_libraries(xrt-pthreads INTERFACE PThreads4W::PThreads4W_CXXEXC)
    else()
    set(CMAKE_THREAD_PREFER_PTHREAD ON)
    find_package(Threads)
    target_link_libraries(xrt-pthreads INTERFACE Threads::Threads)
    endif()
    if(PKGCONFIG_FOUND AND NOT ANDROID)
    # @TODO Turn into a find_package LIBUVC file.
    pkg_check_modules(LIBUVC libuvc)
    # @TODO Turn into a find_package FFMPEG file.
    pkg_check_modules(FFMPEG libavcodec)
    endif()
    find_package(OpenGL)
    set(OPENGL_WITHOUT_GLX_FOUND ${OPENGL_FOUND})
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    set(XRT_HAVE_LINUX YES)
    # Compositor backend
    find_package(X11)
    find_package(udev REQUIRED)
    set(XRT_HAVE_V4L2 TRUE)
    if(PKGCONFIG_FOUND)
    pkg_check_modules(XRANDR xrandr)
    pkg_check_modules(XCB xcb xcb-randr x11-xcb)
    pkg_search_module(WAYLAND wayland-client)
    pkg_search_module(WAYLAND_SCANNER wayland-scanner)
    pkg_search_module(WAYLAND_PROTOCOLS wayland-protocols)
    pkg_search_module(LIBDRM IMPORTED_TARGET libdrm)
    endif()
    find_package(OpenGL COMPONENTS GLX)
    pkg_search_module(DBUS dbus-1)
    pkg_search_module(LIBBSD libbsd)
    pkg_check_modules(GST gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0)
    pkg_check_modules(SURVIVE IMPORTED_TARGET survive)
    endif()
    find_library(RT_LIBRARY rt)
    if(ANDROID)
    find_library(ANDROID_LIBRARY android)
    find_library(ANDROID_LOG_LIBRARY log)
    endif()
    # Find a external SLAM implementation
    set(EXTERNAL_SLAM_SYSTEMS kimera_vio basalt)
    foreach(slam_system IN LISTS EXTERNAL_SLAM_SYSTEMS)
    if(PKGCONFIG_FOUND)
    pkg_check_modules(${slam_system} ${slam_system})
    endif()
    if(${slam_system}_FOUND)
    set(SLAM ON)
    set(SLAM_NAME ${slam_system})
    set(SLAM_LIBRARIES ${${slam_system}_LIBRARIES})
    set(SLAM_INCLUDE_DIRS ${${slam_system}_INCLUDE_DIRS})
    break()
    endif()
    endforeach()
    # ILLIXR
    set(ILLIXR_PATH
    ""
    CACHE PATH "Path to ILLIXR headers"
    )

    这里其实并没有什么重要的内容,但是要记住如果是Android工程,那么

    1
    2
    3
    4
    if(ANDROID)
    find_library(ANDROID_LIBRARY android)
    find_library(ANDROID_LOG_LIBRARY log)
    endif()

    我们是在Android Studio中进行编译的,其实IDE工具帮我们封装好了很多的事情,NDK的部分中有build/cmake/android.toolchain.cmake,其中line 279

    1
    2
    3
    4
    > # Standard cross-compiling stuff.
    > set(ANDROID TRUE)
    > set(CMAKE_SYSTEM_NAME Android)
    >
  • 第三部分就是一些预置option的打开和关闭了

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    option(XRT_FEATURE_COLOR_LOG "Enable logging in color on supported platforms" ON)
    cmake_dependent_option(XRT_HAVE_PERCETTO "Enable percetto support" ON "PERCETTO_FOUND" OFF)
    cmake_dependent_option(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" OFF "XRT_HAVE_PERCETTO" OFF)
    cmake_dependent_option(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" OFF "HAS_IPO" OFF)
    cmake_dependent_option(XRT_HAVE_WAYLAND "Enable Wayland support" ON "WAYLAND_FOUND AND WAYLAND_SCANNER_FOUND AND WAYLAND_PROTOCOLS_FOUND AND LIBDRM_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_WAYLAND_DIRECT "Enable Wayland direct support" ON "XRT_HAVE_WAYLAND AND LIBDRM_FOUND AND WAYLAND_PROTOCOLS_VERSION VERSION_GREATER_EQUAL 1.22" OFF)
    cmake_dependent_option(XRT_HAVE_XLIB "Enable xlib support" ON "X11_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_XRANDR "Enable xlib-xrandr support" ON "XRANDR_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_XCB "Enable xcb support" ON "XCB_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_VULKAN "Enable Vulkan Graphics API support (also needed for compositor)" ON "VULKAN_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_OPENGL "Enable OpenGL Graphics API support" ON "OPENGL_WITHOUT_GLX_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_OPENGL_GLX "Enable OpenGL Graphics API support on X11 (GLX)" ON "XRT_HAVE_OPENGL; OpenGL_GLX_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" ON "OpenGLES_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_EGL "Enable OpenGL(-ES) on EGL Graphics API support" ON "EGL_FOUND; XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES" OFF)
    cmake_dependent_option(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" ON "DBUS_FOUND" OFF)
    cmake_dependent_option(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" ON "XRT_HAVE_VULKAN; XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID OR WIN32" OFF)
    cmake_dependent_option(XRT_HAVE_LIBBSD "Enable libbsd support" ON "LIBBSD_FOUND" OFF)
    cmake_dependent_option(XRT_FEATURE_OPENXR "Build OpenXR runtime target" ON "XRT_FEATURE_COMPOSITOR_MAIN" OFF)
    cmake_dependent_option(XRT_FEATURE_IPC "Enable the build of the IPC layer" ON "NOT WIN32" OFF)
    cmake_dependent_option(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" ON "XRT_FEATURE_IPC AND XRT_FEATURE_OPENXR" OFF)
    cmake_dependent_option(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" ON "Systemd_FOUND AND XRT_FEATURE_SERVICE" OFF)
    cmake_dependent_option(XRT_INSTALL_SYSTEMD_UNIT_FILES "Install user unit files for systemd socket activation on installation" ON "XRT_HAVE_SYSTEMD" OFF)
    cmake_dependent_option(XRT_INSTALL_ABSOLUTE_SYSTEMD_UNIT_FILES "Use an absolute path to monado-system in installed user unit files for systemd socket activation" ON "XRT_INSTALL_SYSTEMD_UNIT_FILES" OFF)
    cmake_dependent_option(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" ON "NOT ANDROID" OFF)
    if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_DEPTH)
    set(XRT_FEATURE_OPENXR_LAYER_DEPTH ON)
    endif()
    if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_CUBE)
    set(XRT_FEATURE_OPENXR_LAYER_CUBE OFF)
    endif()
    if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_CYLINDER)
    set(XRT_FEATURE_OPENXR_LAYER_CYLINDER ON)
    endif()
    if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_EQUIRECT2)
    set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT2 ON)
    endif()
    if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_EQUIRECT1)
    set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 ON)
    endif()
    # Most users won't touch these.
    mark_as_advanced(XRT_FEATURE_COMPOSITOR_MAIN XRT_FEATURE_OPENXR)
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    set(XRT_HAVE_LIBUDEV ON)
    set(XRT_HAVE_INTERNAL_HID ON)
    else()
    cmake_dependent_option(XRT_HAVE_LIBUDEV "Enable libudev (used for device probing on Linux)" ON "UDEV_FOUND" OFF)
    endif()
    cmake_dependent_option(XRT_HAVE_LIBUSB "Enable libusb (used for most drivers)" ON "LIBUSB1_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_JPEG "Enable jpeg code (used for some video drivers)" ON "JPEG_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_OPENCV "Enable OpenCV backend" ON "OpenCV_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_LIBUVC "Enable libuvc video driver" ON "LIBUVC_FOUND AND XRT_HAVE_LIBUSB" OFF)
    cmake_dependent_option(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" ON "FFMPEG_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_SDL2 "Enable use of SDL2" ON "SDL2_FOUND AND XRT_HAVE_OPENGL" OFF)
    cmake_dependent_option(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" ON "CJSON_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_GST "Enable gstreamer" ON "GST_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_REALSENSE "Enable RealSense support" ON "realsense2_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_ONNXRUNTIME "Enable ONNX runtime support" ON "ONNXRUNTIME_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_KIMERA_SLAM "Enable Kimera support" ON "kimera_vio_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_BASALT_SLAM "Enable Basalt support" ON "basalt_FOUND" OFF)
    cmake_dependent_option(XRT_HAVE_SLAM "Enable SLAM tracking support" ON "SLAM;XRT_HAVE_OPENCV" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" ON "HIDAPI_FOUND" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_REALSENSE "Enable RealSense device driver" ON "XRT_HAVE_REALSENSE" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Valve Index, and their controllers" ON "ZLIB_FOUND AND XRT_HAVE_LINUX" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_OHMD "Enable OpenHMD driver" ON "OPENHMD_FOUND" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_HANDTRACKING "Enable Camera Hand Tracking driver" ON "XRT_HAVE_ONNXRUNTIME AND XRT_HAVE_OPENCV AND XRT_HAVE_V4L2" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" ON "XRT_HAVE_DBUS" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" ON "XRT_HAVE_DBUS" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" ON "ILLIXR_PATH" OFF)
    option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON)
    cmake_dependent_option(XRT_BUILD_DRIVER_ULV2 "Enable Ultraleap v2 driver" ON "LeapV2_FOUND" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" ON "XRT_HAVE_LINUX OR ANDROID" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" ON "NOT WIN32" OFF)
    option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON)
    # These all use the Monado internal hid wrapper.
    cmake_dependent_option(XRT_BUILD_DRIVER_HDK "Enable HDK driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_NS "Enable North Star driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" ON "XRT_HAVE_GST" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_DEPTHAI "DepthAI" ON "depthai_FOUND" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" ON "SURVIVE_FOUND" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" ON "ANDROID" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" ON "XRT_HAVE_SDL2" OFF)
    cmake_dependent_option(XRT_BUILD_DRIVER_EUROC "Enable EuRoC dataset driver for SLAM evaluation" ON "XRT_HAVE_OPENCV" OFF)

    表达式cmake_dependent_option的含义是:cmake_dependent_option(OPT_VAR "OPT_VAR_DES" DEF_VAL_1 "CONDITION_EXP" DEF_VAR_2)

    其中OPT_VAR的值会取决于"CONDITION_EXP",如果这个值为True,那么OPT_VAR的值就是DEF_VAL_1,如果为False,那就是DEF_VAR_2

其中的变量推导和计算我们就忽略了,直接最后的message输出:src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/x86_64/cmake_server_log.txt

这个输出的部分其实是第五部分的内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
GIT_DESC : v21.0.0-1291-g72e0ccb7
XRT_HAVE_GST : OFF
XRT_HAVE_WAYLAND : OFF
XRT_HAVE_WAYLAND_DIRECT : OFF
XRT_HAVE_XLIB : OFF
XRT_HAVE_XRANDR : OFF
XRT_HAVE_XCB : OFF
XRT_HAVE_VULKAN : ON
XRT_HAVE_OPENGL : OFF
XRT_HAVE_OPENGL_GLX : OFF
XRT_HAVE_OPENGLES : ON
XRT_HAVE_EGL : ON
XRT_HAVE_DBUS : OFF
XRT_HAVE_LIBBSD : OFF
XRT_HAVE_SYSTEMD : OFF
XRT_HAVE_LIBUSB : OFF
XRT_HAVE_JPEG : OFF
XRT_HAVE_OPENCV : OFF
XRT_HAVE_LIBUVC : OFF
XRT_HAVE_FFMPEG : OFF
XRT_HAVE_SDL2 : OFF
XRT_HAVE_PERCETTO : OFF
XRT_HAVE_REALSENSE : OFF
XRT_HAVE_ONNXRUNTIME : OFF
XRT_HAVE_SYSTEM_CJSON : OFF
XRT_HAVE_KIMERA_SLAM : OFF
XRT_HAVE_BASALT_SLAM : OFF
XRT_HAVE_SLAM : OFF
XRT_FEATURE_IPC : ON
XRT_FEATURE_COMPOSITOR_MAIN : ON
XRT_FEATURE_SERVICE : OFF
XRT_FEATURE_OPENXR : ON
XRT_FEATURE_OPENXR_LAYER_DEPTH : ON
XRT_FEATURE_OPENXR_LAYER_CUBE : OFF
XRT_FEATURE_OPENXR_LAYER_CYLINDER : ON
XRT_FEATURE_OPENXR_LAYER_EQUIRECT2 : ON
XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 : ON
XRT_FEATURE_STEAMVR_PLUGIN : OFF
XRT_FEATURE_COLOR_LOG : ON
XRT_FEATURE_TRACING : OFF
XRT_BUILD_DRIVER_ANDROID : ON
XRT_BUILD_DRIVER_ARDUINO : OFF
XRT_BUILD_DRIVER_DAYDREAM : OFF
XRT_BUILD_DRIVER_DUMMY : ON
XRT_BUILD_DRIVER_HANDTRACKING : OFF
XRT_BUILD_DRIVER_HDK : OFF
XRT_BUILD_DRIVER_HYDRA : OFF
XRT_BUILD_DRIVER_ILLIXR : OFF
XRT_BUILD_DRIVER_NS : OFF
XRT_BUILD_DRIVER_ULV2 : OFF
XRT_BUILD_DRIVER_OHMD : OFF
XRT_BUILD_DRIVER_PSMV : OFF
XRT_BUILD_DRIVER_PSVR : OFF
XRT_BUILD_DRIVER_REALSENSE : OFF
XRT_BUILD_DRIVER_REMOTE : ON
XRT_BUILD_DRIVER_SURVIVE : OFF
XRT_BUILD_DRIVER_VF : OFF
XRT_BUILD_DRIVER_DEPTHAI : OFF
XRT_BUILD_DRIVER_VIVE : OFF
XRT_BUILD_DRIVER_QWERTY : OFF
XRT_BUILD_DRIVER_WMR : ON
XRT_BUILD_DRIVER_EUROC : OFF
  • 第四部分是真正项目编译有关的了,其中定义XRT_ANDROID_PACKAGE,可以看出是根据我们的Flavor来的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    if(ANDROID AND NOT XRT_ANDROID_PACKAGE)
    if(XRT_FEATURE_SERVICE)
    set(XRT_ANDROID_PACKAGE "org.freedesktop.monado.openxr_runtime.out_of_process")
    else()
    set(XRT_ANDROID_PACKAGE "org.freedesktop.monado.openxr_runtime.in_process")
    endif()
    endif()
    if(ANDROID)
    set(VK_USE_PLATFORM_ANDROID_KHR TRUE)
    endif()
    ###
    # Descend into the source
    ###
    add_subdirectory(src)
    add_subdirectory(doc)
  • 最后它留了一个伏笔,add_subdirectory(src)

因此,整个根目录下的CMakeList其实是完成了大部分的宏定义,并且引出了整个编译的subdirectory,也即src目录

src

其中monado/src/CMakeLists.txt的内容

1
2
add_subdirectory(external)
add_subdirectory(xrt)

src/external

monado/src/external/CMakeLists.txt中大部分都是add_library,按照顺序依次分析

  • Catch2

    1
    2
    3
    4
    5
    6
    # Copyright 2020, Collabora, Ltd.
    # SPDX-License-Identifier: BSL-1.0
    # Catch2
    add_library(xrt-external-catch2 INTERFACE)
    target_include_directories(xrt-external-catch2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Catch2)
  • openvr

    1
    2
    3
    4
    add_library(xrt-external-openvr INTERFACE)
    target_include_directories(
    xrt-external-openvr INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/openvr_includes
    )
  • cJSON:XRT_HAVE_SYSTEM_CJSON:OFF

    1
    2
    3
    4
    5
    6
    7
    8
    # cJSON
    add_library(xrt-external-cjson INTERFACE)
    if(XRT_HAVE_SYSTEM_CJSON)
    target_link_libraries(xrt-external-cjson INTERFACE cJSON::cJSON)
    else()
    target_include_directories(xrt-external-cjson INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cjson)
    target_compile_definitions(xrt-external-cjson INTERFACE CJSON_HIDE_SYMBOLS)
    endif()
  • FlexKalman

    1
    2
    3
    # FlexKalman
    add_library(xrt-external-flexkalman INTERFACE)
    target_include_directories(xrt-external-flexkalman INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/flexkalman)
  • Glad

    1
    2
    3
    # Glad
    add_library(xrt-external-glad INTERFACE)
    target_include_directories(xrt-external-glad INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)
  • Hungarian graph algorithm

    1
    2
    3
    # Hungarian graph algorithm
    add_library(xrt-external-hungarian INTERFACE)
    target_include_directories(xrt-external-hungarian INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/hungarian)
  • JNIPP and Android JNI wrappers

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # JNIPP and Android JNI wrappers
    if(ANDROID)
    add_library(xrt-external-jnipp STATIC jnipp/jnipp.cpp)
    target_include_directories(xrt-external-jnipp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/jnipp)
    file(GLOB WRAP_SOURCES android-jni-wrap/wrap/*.cpp)
    add_library(xrt-external-jni-wrap STATIC ${WRAP_SOURCES})
    target_include_directories(
    xrt-external-jni-wrap PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/android-jni-wrap
    )
    target_link_libraries(xrt-external-jni-wrap PUBLIC xrt-external-jnipp)
    endif()
  • OpenXR

    1
    2
    3
    4
    5
    # OpenXR
    add_library(xrt-external-openxr INTERFACE)
    target_include_directories(
    xrt-external-openxr INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/openxr_includes
    )
  • External SLAM tracking:

    • cmake_dependent_option(XRT_HAVE_SLAM "Enable SLAM tracking support" ON "SLAM;XRT_HAVE_OPENCV" OFF)
    • 因为XRT_HAVE_SLAM = OFF,从而我们推导出SLAM=OFF
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # External SLAM tracking
    if(SLAM)
    add_library(xrt-external-slam STATIC slam_tracker/slam_tracker.hpp)
    set_target_properties(xrt-external-slam PROPERTIES LINKER_LANGUAGE CXX)
    target_include_directories(
    xrt-external-slam INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/slam_tracker
    )
    target_include_directories(xrt-external-slam INTERFACE ${SLAM_INCLUDE_DIRS})
    target_link_libraries(xrt-external-slam INTERFACE ${SLAM_LIBRARIES})
    endif()
  • STB

    1
    2
    3
    # STB
    add_library(xrt-external-stb INTERFACE)
    target_include_directories(xrt-external-stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/stb)
  • imgui:XRT_HAVE_OPENGL:OFF

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    # imgui
    if(XRT_HAVE_OPENGL)
    add_library(
    xrt-external-imgui STATIC
    imgui/imgui/cimgui.cpp
    imgui/imgui/cimgui.h
    imgui/imgui/cimplot.cpp
    imgui/imgui/cimplot.h
    imgui/imgui/imconfig.h
    imgui/imgui/imgui.cpp
    imgui/imgui/imgui.h
    imgui/imgui/imgui_demo.cpp
    imgui/imgui/imgui_draw.cpp
    imgui/imgui/imgui_impl_opengl3.cpp
    imgui/imgui/imgui_impl_opengl3.h
    imgui/imgui/imgui_internal.h
    imgui/imgui/imgui_widgets.cpp
    imgui/imgui/implot.cpp
    imgui/imgui/implot.h
    imgui/imgui/implot_demo.cpp
    imgui/imgui/implot_internal.h
    imgui/imgui/implot_items.cpp
    imgui/imgui/imstb_rectpack.h
    imgui/imgui/imstb_textedit.h
    imgui/imgui/imstb_truetype.h
    imgui/imgui_monado/imgui_monado.cpp
    )
    target_include_directories(
    xrt-external-imgui SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui
    )
    target_include_directories(xrt-external-imgui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
    target_compile_definitions(xrt-external-imgui PUBLIC CIMGUI_NO_EXPORT)
    set_target_properties(xrt-external-imgui PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
    target_link_libraries(xrt-external-imgui PUBLIC xrt-external-glad)
    if(XRT_HAVE_SDL2)
    add_library(
    xrt-external-imgui-sdl2 STATIC
    imgui/imgui/cimgui_sdl.cpp imgui/imgui/imgui_impl_sdl.cpp
    imgui/imgui/imgui_impl_sdl.h
    )
    target_link_libraries(
    xrt-external-imgui-sdl2
    PUBLIC xrt-external-imgui
    PUBLIC ${SDL2_LIBRARIES}
    )
    target_include_directories(xrt-external-imgui-sdl2 PUBLIC ${SDL2_INCLUDE_DIRS})
    target_include_directories(
    xrt-external-imgui-sdl2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui
    )
    set_target_properties(
    xrt-external-imgui-sdl2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF
    )
    endif()
    endif()

在这里需要注意的是,真正参与编译的library中,只有JNIPP and Android JNI wrappers是使用的STATIC关键字:

  • add_library(xrt-external-jnipp STATIC jnipp/jnipp.cpp)
  • add_library(xrt-external-jni-wrap STATIC ${WRAP_SOURCES})

这两个库最终都会被link到xrt-external-jni-wrap

  • target_link_libraries(xrt-external-jni-wrap PUBLIC xrt-external-jnipp)

其余的模块都是使用的INTERFACE关键字:

  • add_library(xrt-external-catch2 INTERFACE)
  • add_library(xrt-external-catch2 INTERFACE)
  • add_library(xrt-external-openvr INTERFACE)
  • add_library(xrt-external-cjson INTERFACE)
  • add_library(xrt-external-flexkalman INTERFACE)
  • add_library(xrt-external-glad INTERFACE)
  • add_library(xrt-external-hungarian INTERFACE)
  • add_library(xrt-external-openxr INTERFACE)
  • add_library(xrt-external-stb INTERFACE)

以上是整个extrnal模块的分析,可以看出来实质上是编译了android jni的wrap库。

src/xrt

重要的部分其实是在monado/src/xrt/CMakeLists.txt,其中:XRT_FEATURE_IPC:ON

1
2
3
4
5
6
7
8
9
10
11
12
# Copyright 2019, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
add_subdirectory(include)
add_subdirectory(auxiliary)
add_subdirectory(drivers)
add_subdirectory(compositor)
add_subdirectory(state_trackers)
add_subdirectory(targets)
if(XRT_FEATURE_IPC)
add_subdirectory(ipc)
endif()

这个部分只能挨个来拆解看一下。

include

monado/src/xrt/include/CMakeLists.txt

1
2
3
4
5
6
7
8
9
# Copyright 2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
add_subdirectory(xrt)
add_library(xrt-interfaces INTERFACE)
target_include_directories(
xrt-interfaces INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
)

xrt

monado/src/xrt/include/xrt/CMakeLists.txt,这个cmake依旧做了一个INTERFACE的library,再看一下include/xrt/CMakeLists.txt的内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include/xrt/CMakeLists.txt
#Copyright 2020-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
# Generate a header containing defines for each enabled driver
set(FILE_CONTENTS "")
foreach(driver ${AVAILABLE_DRIVERS})
if(XRT_BUILD_DRIVER_${driver})
string(APPEND FILE_CONTENTS "#define XRT_BUILD_DRIVER_${driver}\n")
endif()
endforeach()
# First setup all of the config headers.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/xrt_config_drivers.h.cmake_in
${CMAKE_CURRENT_BINARY_DIR}/xrt_config_drivers.h @ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/xrt_config_have.h.cmake_in
${CMAKE_CURRENT_BINARY_DIR}/xrt_config_have.h @ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/xrt_config_build.h.cmake_in
${CMAKE_CURRENT_BINARY_DIR}/xrt_config_build.h @ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/xrt_config_vulkan.h.cmake_in
${CMAKE_CURRENT_BINARY_DIR}/xrt_config_vulkan.h @ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/xrt_config_android.h.cmake_in
${CMAKE_CURRENT_BINARY_DIR}/xrt_config_android.h @ONLY
)

根据我们先前的解析和定义,其中以XRT_BUILD_DRIVER_开头的driver定义为ON的:

  • XRT_BUILD_DRIVER_ANDROID:ON
  • XRT_BUILD_DRIVER_DUMMY:ON
  • XRT_BUILD_DRIVER_REMOTE:ON
  • XRT_BUILD_DRIVER_WMR:ON

因此,这个模块其实就是定义了四个宏:

  • #define XRT_BUILD_DRIVER_ANDROID
  • #define XRT_BUILD_DRIVER_DUMMY
  • #define XRT_BUILD_DRIVER_REMOTE
  • #define XRT_BUILD_DRIVER_WMR

接着看include/xrt/CMakeLists.txt的第二部分configure_file,这个部分其实是做文件的copy,并把其中的一些变量做一下替换,简单来看看两个文件。

  • ./src/xrt/include/xrt/xrt_config_android.h.cmake_in

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    // Copyright 2020, Collabora, Ltd.
    // SPDX-License-Identifier: BSL-1.0
    /*!
    * @file
    * @brief Android defines.
    * @author Ryan Pavlik <ryan.pavlik@collabora.com>
    * @ingroup xrt_iface
    */
    #pragma once
    #cmakedefine XRT_ANDROID_PACKAGE "@XRT_ANDROID_PACKAGE@"
    • 生成文件src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/arm64-v8a/src/xrt/include/xrt/xrt_config_android.h

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      // Copyright 2020, Collabora, Ltd.
      // SPDX-License-Identifier: BSL-1.0
      /*!
      * @file
      * @brief Android defines.
      * @author Ryan Pavlik <ryan.pavlik@collabora.com>
      * @ingroup xrt_iface
      */
      #pragma once
      #define XRT_ANDROID_PACKAGE "org.freedesktop.monado.openxr_runtime.in_process"
  • ./src/xrt/include/xrt/xrt_config_drivers.h.cmake_in

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    // Copyright 2019-2020, Collabora, Ltd.
    // SPDX-License-Identifier: BSL-1.0
    /*!
    * @file
    * @brief What drivers are we building.
    * @author Jakob Bornecrantz <jakob@collabora.com>
    * @ingroup xrt_iface
    */
    #pragma once
    @FILE_CONTENTS@
    • 生成文件src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/arm64-v8a/src/xrt/include/xrt/xrt_config_drivers.h

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      // Copyright 2019-2020, Collabora, Ltd.
      // SPDX-License-Identifier: BSL-1.0
      /*!
      * @file
      * @brief What drivers are we building.
      * @author Jakob Bornecrantz <jakob@collabora.com>
      * @ingroup xrt_iface
      */
      #pragma once
      #define XRT_BUILD_DRIVER_ANDROID
      #define XRT_BUILD_DRIVER_DUMMY
      #define XRT_BUILD_DRIVER_REMOTE
      #define XRT_BUILD_DRIVER_WMR

      @FILE_CONTENTS@,其实在include/src/CMakeLists.txt中的for循环中有定义了

      1
      2
      3
      4
      5
      6
      7
      > set(FILE_CONTENTS "")
      > foreach(driver ${AVAILABLE_DRIVERS})
      > if(XRT_BUILD_DRIVER_${driver})
      > string(APPEND FILE_CONTENTS "#define XRT_BUILD_DRIVER_${driver}\n")
      > endif()
      > endforeach()
      >

auxiliary

monado/src/xrt/auxiliary/CMakeLists.txt,这个CMakeLists的部分有点长,拆开来分析一下

  • 首先是又增加了一个目录引用:add_subdirectory(bindings)

    1
    2
    3
    4
    # Copyright 2019-2021, Collabora, Ltd.
    # SPDX-License-Identifier: BSL-1.0
    add_subdirectory(bindings)

bindings

monado/src/xrt/auxiliary/bindings/CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright 2019-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
# Binding generation: pass filename to generate
function(bindings_gen output)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${output}"
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/bindings.py
${CMAKE_CURRENT_SOURCE_DIR}/bindings.json
"${CMAKE_CURRENT_BINARY_DIR}/${output}"
VERBATIM
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bindings.py
${CMAKE_CURRENT_SOURCE_DIR}/bindings.json
COMMENT "Generating ${output}"
)
endfunction()
bindings_gen(b_generated_bindings.h)
bindings_gen(b_generated_bindings.c)
# Bindings library.
add_library(
aux_generated_bindings STATIC ${CMAKE_CURRENT_BINARY_DIR}/b_generated_bindings.c
${CMAKE_CURRENT_BINARY_DIR}/b_generated_bindings.h
)
# needed globally for steamvr input profile generation in steamvr target
set_property(GLOBAL PROPERTY AUX_BINDINGS_DIR_PROP "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(aux_generated_bindings PRIVATE xrt-interfaces aux_util)
  • 通过阅读src/xrt/auxiliary/bindings/bindings.json可以知道,这一段其实是通过json文件生成c语言级别的解析函数。

回到monado/src/xrt/auxiliary/CMakeLists.txt

  • Common includes

    1
    2
    3
    4
    5
    6
    # Common includes
    add_library(aux-includes INTERFACE)
    target_include_directories(
    aux-includes INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
    )
    target_link_libraries(aux-includes INTERFACE xrt-interfaces)
  • OpenGL library:XRT_HAVE_OPENGLES:ONXRT_HAVE_EGL:ON

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    # OpenGL library.
    if(XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES)
    add_library(
    aux_ogl STATIC
    ogl/ogl_documentation.h
    ogl/ogl_api.c
    ogl/ogl_api.h
    ogl/ogl_helpers.c
    ogl/ogl_helpers.h
    )
    target_link_libraries(aux_ogl PUBLIC aux-includes xrt-external-glad)
    if(XRT_HAVE_EGL)
    target_sources(aux_ogl PRIVATE ogl/egl_api.c ogl/egl_api.h)
    endif()
    if(XRT_HAVE_OPENGLES)
    target_link_libraries(aux_ogl PUBLIC EGL::EGL)
    endif()
    endif()
  • Math library

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    # Math library.
    add_library(
    aux_math STATIC
    math/m_api.h
    math/m_base.cpp
    math/m_eigen_interop.hpp
    math/m_filter_fifo.c
    math/m_filter_fifo.h
    math/m_filter_one_euro.c
    math/m_filter_one_euro.h
    math/m_hash.cpp
    math/m_imu_3dof.c
    math/m_imu_3dof.h
    math/m_imu_pre.c
    math/m_imu_pre.h
    math/m_optics.c
    math/m_permutation.c
    math/m_permutation.h
    math/m_predict.c
    math/m_predict.h
    math/m_quatexpmap.cpp
    math/m_relation_history.h
    math/m_relation_history.cpp
    math/m_space.cpp
    math/m_space.h
    math/m_vec2.h
    math/m_vec3.h
    )
    target_link_libraries(aux_math PUBLIC aux-includes aux_util)
    target_include_directories(aux_math SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})
  • OS library:XRT_HAVE_DBUS:OFF

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    # OS library.
    add_library(
    aux_os STATIC
    os/os_ble.h
    os/os_documentation.h
    os/os_hid.h
    os/os_hid_hidraw.c
    os/os_threading.h
    )
    target_link_libraries(aux_os PUBLIC aux-includes xrt-pthreads)
    if(XRT_HAVE_DBUS)
    target_sources(aux_os PRIVATE os/os_ble_dbus.c)
    target_link_libraries(aux_os PRIVATE ${DBUS_LIBRARIES})
    target_include_directories(aux_os SYSTEM PRIVATE ${DBUS_INCLUDE_DIRS})
    endif()
  • GStreamer library:XRT_HAVE_GST:OFF

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # GStreamer library.
    if(XRT_HAVE_GST)
    add_library(
    aux_gstreamer STATIC
    gstreamer/gst_internal.h
    gstreamer/gst_sink.h
    gstreamer/gst_sink.c
    gstreamer/gst_pipeline.h
    gstreamer/gst_pipeline.c
    )
    target_link_libraries(aux_gstreamer PUBLIC aux-includes)
    target_link_libraries(aux_gstreamer PRIVATE xrt-interfaces aux_math aux_os ${GST_LIBRARIES})
    target_include_directories(aux_gstreamer PRIVATE ${GST_INCLUDE_DIRS})
    endif()
  • Tracking library

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    # Tracking library.
    add_library(
    aux_tracking STATIC
    tracking/t_data_utils.c
    tracking/t_imu_fusion.hpp
    tracking/t_imu.cpp
    tracking/t_imu.h
    tracking/t_lowpass_vector.hpp
    tracking/t_lowpass.hpp
    tracking/t_tracking.h
    )
    target_link_libraries(
    aux_tracking
    PUBLIC aux-includes xrt-external-cjson
    PRIVATE aux_math aux_util xrt-external-flexkalman xrt-external-hungarian
    )
    target_include_directories(aux_tracking SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})
  • OpenCV,XRT_HAVE_OPENCV:OFF

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    if(XRT_HAVE_OPENCV)
    target_sources(
    aux_tracking
    PRIVATE
    tracking/t_calibration_opencv.hpp
    tracking/t_calibration.cpp
    tracking/t_convert.cpp
    tracking/t_debug_hsv_filter.cpp
    tracking/t_debug_hsv_picker.cpp
    tracking/t_debug_hsv_viewer.cpp
    tracking/t_euroc_recorder.cpp
    tracking/t_euroc_recorder.h
    tracking/t_file.cpp
    tracking/t_frame_cv_mat_wrapper.cpp
    tracking/t_frame_cv_mat_wrapper.hpp
    tracking/t_fusion.hpp
    tracking/t_helper_debug_sink.hpp
    tracking/t_hsv_filter.c
    tracking/t_kalman.cpp
    tracking/t_tracker_psmv_fusion.hpp
    tracking/t_tracker_psmv.cpp
    tracking/t_tracker_psvr.cpp
    tracking/t_tracker_hand.cpp
    )
    target_include_directories(aux_tracking SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})
    target_link_libraries(aux_tracking PUBLIC ${OpenCV_LIBRARIES})
    endif()
  • SLAM,XRT_HAVE_SLAM:OFF

    1
    2
    3
    4
    if(XRT_HAVE_SLAM)
    target_sources(aux_tracking PRIVATE tracking/t_tracker_slam.cpp)
    target_link_libraries(aux_tracking PRIVATE xrt-external-slam)
    endif()
  • Util library

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    # Util library.
    add_library(
    aux_util STATIC
    util/u_bitwise.c
    util/u_bitwise.h
    util/u_debug.c
    util/u_debug.h
    util/u_device.c
    util/u_device.h
    util/u_distortion.c
    util/u_distortion.h
    util/u_distortion_mesh.c
    util/u_distortion_mesh.h
    util/u_documentation.h
    util/u_file.c
    util/u_file.cpp
    util/u_file.h
    util/u_format.c
    util/u_format.h
    util/u_frame.c
    util/u_frame.h
    util/u_generic_callbacks.hpp
    util/u_git_tag.h
    util/u_hand_tracking.c
    util/u_hand_tracking.h
    util/u_handles.c
    util/u_handles.h
    util/u_hashmap.cpp
    util/u_hashmap.h
    util/u_hashset.cpp
    util/u_hashset.h
    util/u_json.c
    util/u_json.h
    util/u_json.hpp
    util/u_logging.c
    util/u_logging.h
    util/u_misc.c
    util/u_misc.h
    util/u_pacing.h
    util/u_pacing_app.c
    util/u_pacing_compositor.c
    util/u_pacing_compositor_fake.c
    util/u_sink.h
    util/u_sink_combiner.c
    util/u_sink_converter.c
    util/u_sink_deinterleaver.c
    util/u_sink_queue.c
    util/u_sink_quirk.c
    util/u_sink_split.c
    util/u_string_list.cpp
    util/u_string_list.h
    util/u_string_list.hpp
    util/u_template_historybuf.hpp
    util/u_time.cpp
    util/u_time.h
    util/u_trace_marker.c
    util/u_trace_marker.h
    util/u_var.cpp
    util/u_var.h
    util/u_config_json.c
    util/u_config_json.h
    util/u_verify.h
    util/u_process.c
    util/u_process.h
    "${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c"
    )
    configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/util/u_git_tag.c.in" "${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c"
    @ONLY
    )
    target_link_libraries(aux_util PUBLIC aux-includes xrt-pthreads aux_generated_bindings aux_math)

    XRT_HAVE_JPEG:OFF

    1
    2
    3
    4
    if(XRT_HAVE_JPEG)
    target_link_libraries(aux_util PRIVATE ${JPEG_LIBRARIES})
    target_include_directories(aux_util PRIVATE ${JPEG_INCLUDE_DIRS})
    endif()

    XRT_HAVE_SYSTEM_CJSON:OFF

    1
    2
    3
    4
    5
    6
    if(XRT_HAVE_SYSTEM_CJSON)
    target_link_libraries(aux_util PUBLIC cJSON::cJSON)
    target_compile_definitions(aux_util PRIVATE XRT_HAVE_SYSTEM_CJSON)
    else()
    target_link_libraries(aux_util PUBLIC xrt-external-cjson)
    endif()

    XRT_FEATURE_TRACING:OFFXRT_HAVE_PERCETTO:OFF

    1
    2
    3
    if(XRT_FEATURE_TRACING AND XRT_HAVE_PERCETTO)
    target_link_libraries(aux_util PUBLIC Percetto::percetto)
    endif()

    XRT_HAVE_LIBBSD:OFF

    1
    2
    3
    4
    if(XRT_HAVE_LIBBSD)
    target_include_directories(aux_util SYSTEM PRIVATE ${LIBBSD_INCLUDE_DIRS})
    target_link_libraries(aux_util PUBLIC ${LIBBSD_LIBRARIES})
    endif()

    ANDROID:ON

    1
    2
    3
    if(ANDROID)
    target_link_libraries(aux_util PUBLIC ${ANDROID_LOG_LIBRARY})
    endif()
  • Vulkan library,XRT_HAVE_VULKAN:ON,ANDROID=ON

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    if(XRT_HAVE_VULKAN)
    # Vulkan library.
    add_library(
    aux_vk STATIC
    vk/vk_command_buffer.c
    vk/vk_documentation.h
    vk/vk_helpers.c
    vk/vk_helpers.h
    vk/vk_image_allocator.c
    vk/vk_image_allocator.h
    vk/vk_state_creators.c
    )
    target_link_libraries(aux_vk PUBLIC aux_os aux_util)
    target_link_libraries(aux_vk PUBLIC Vulkan::Vulkan)
    target_include_directories(aux_vk PUBLIC ${Vulkan_INCLUDE_DIR})
    if(ANDROID)
    target_link_libraries(aux_vk PUBLIC ${ANDROID_LIBRARY})
    endif()
    endif()
  • ViVE/SURVIVE Drivers,XRT_BUILD_DRIVER_VIVE:OFFXRT_BUILD_DRIVER_SURVIVE:OFF

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    if(XRT_BUILD_DRIVER_VIVE OR XRT_BUILD_DRIVER_SURVIVE)
    set(VIVE_CONFIG_SOURCE_FILES vive/vive_config.h vive/vive_config.c)
    add_library(aux_vive STATIC ${VIVE_CONFIG_SOURCE_FILES})
    target_link_libraries(
    aux_vive
    PRIVATE
    xrt-interfaces
    aux_util
    aux_math
    aux_tracking
    xrt-external-cjson
    ${ZLIB_LIBRARIES}
    )
    target_include_directories(aux_vive PRIVATE ${ZLIB_INCLUDE_DIRS})
    endif()
  • aux_vk,aux_android

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    if(ANDROID)
    add_library(
    android_app_glue STATIC
    ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
    )
    target_include_directories(
    android_app_glue PUBLIC ${ANDROID_NDK}/sources/android/native_app_glue
    )
    # disable these warnings in external code
    target_compile_options(android_app_glue PRIVATE -Wno-format-pedantic)
    add_library(
    aux_android STATIC
    android/android_ahardwarebuffer_allocator.c
    android/android_ahardwarebuffer_allocator.h
    android/android_custom_surface.cpp
    android/android_custom_surface.h
    android/android_globals.cpp
    android/android_globals.h
    android/android_load_class.cpp
    android/android_load_class.hpp
    android/android_looper.cpp
    android/android_looper.h
    android/org.freedesktop.monado.auxiliary.cpp
    android/org.freedesktop.monado.auxiliary.hpp
    android/org.freedesktop.monado.auxiliary.impl.hpp
    )
    target_link_libraries(
    aux_android
    PUBLIC aux_util
    PRIVATE
    ${ANDROID_LIBRARY}
    ${ANDROID_LOG_LIBRARY}
    xrt-external-jni-wrap
    xrt-external-jnipp
    android_app_glue
    )
    target_link_libraries(aux_vk PUBLIC aux_android)
    endif()

整个编译的CMakeLists非常长,但是其中真正编译出来的部分其实是

  • add_library(aux_ogl STATIC XXXX)
  • add_library(aux_math STATIC XXXX)
  • add_library(aux_tracking STATIC XXXX)
  • add_library(aux_util STATIC XXXX)
  • add_library(aux_vk STATIC XXXX)
  • add_library(android_app_glue STATIC XXXX)
  • add_library(aux_android STATIC XXXX)

小结:从这里现在还无法判断出有哪些最终的target,但是从auxiliary的定义来说,是辅助工具类,所以这里大部分的target其实给其他模块做link使用的,这个可以在后面的CMakeList.txt中看到

drivers

monado/src/xrt/drivers/CMakeLists.txt,drivers的部分依旧非常长,由最早monado/CMakeLists.txt中的定义,我们可知:

  • XRT_BUILD_DRIVER_ARDUINO
  • XRT_BUILD_DRIVER_DAYDREAM
  • XRT_BUILD_DRIVER_DEPTHAI
  • XRT_BUILD_DRIVER_QWERTY
  • XRT_BUILD_DRIVER_HDK
  • XRT_BUILD_DRIVER_HYDRA
  • XRT_BUILD_DRIVER_NS
  • XRT_BUILD_DRIVER_ULV2
  • XRT_BUILD_DRIVER_OHMD
  • XRT_BUILD_DRIVER_PSMV
  • XRT_BUILD_DRIVER_PSVR
  • XRT_BUILD_DRIVER_REALSENSE
  • XRT_BUILD_DRIVER_VIVE
  • XRT_HAVE_V4L2
  • XRT_BUILD_DRIVER_VF
  • XRT_BUILD_DRIVER_HANDTRACKING
  • XRT_BUILD_DRIVER_SURVIVE
  • XRT_BUILD_DRIVER_ILLIXR
  • XRT_BUILD_DRIVER_EUROC

都是OFF的状态,所以整个CMakeLists.txt被简化为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright 2019-2021, Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
set(ENABLED_HEADSET_DRIVERS)
set(ENABLED_DRIVERS)
add_library(drv_includes INTERFACE)
target_include_directories(drv_includes INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
if(XRT_BUILD_DRIVER_DUMMY)
add_library(drv_dummy STATIC dummy/dummy_hmd.c dummy/dummy_interface.h dummy/dummy_prober.c)
target_link_libraries(drv_dummy PRIVATE xrt-interfaces aux_util)
list(APPEND ENABLED_HEADSET_DRIVERS dummy)
endif()
if(XRT_BUILD_DRIVER_REMOTE)
add_library(
drv_remote STATIC
remote/r_device.c
remote/r_hmd.c
remote/r_hub.c
remote/r_interface.h
remote/r_internal.h
)
target_link_libraries(drv_remote PRIVATE xrt-interfaces aux_util)
list(APPEND ENABLED_HEADSET_DRIVERS remote)
endif()
set(VIVE_CONFIG_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/vive")
if(XRT_BUILD_DRIVER_ANDROID)
add_library(
drv_android STATIC android/android_prober.c android/android_prober.h
android/android_sensors.c android/android_sensors.h
)
target_link_libraries(
drv_android
PRIVATE
xrt-interfaces
aux_util
aux_os
aux_android
${ANDROID_LIBRARY}
)
list(APPEND ENABLED_DRIVERS android)
endif()
add_library(drv_multi STATIC multi_wrapper/multi.c multi_wrapper/multi.h)
target_link_libraries(drv_multi PUBLIC xrt-interfaces aux_util)
list(APPEND ENABLED_HEADSET_DRIVERS drv_multi)
if(XRT_BUILD_DRIVER_WMR)
add_library(
drv_wmr STATIC
wmr/wmr_camera.h
wmr/wmr_common.h
wmr/wmr_config.c
wmr/wmr_config.h
wmr/wmr_bt_controller.c
wmr/wmr_bt_controller.h
wmr/wmr_hmd.c
wmr/wmr_hmd.h
wmr/wmr_interface.h
wmr/wmr_prober.c
wmr/wmr_protocol.c
wmr/wmr_protocol.h
wmr/wmr_controller_protocol.c
wmr/wmr_controller_protocol.h
wmr/wmr_source.c
wmr/wmr_source.h
)
target_link_libraries(drv_wmr PRIVATE xrt-interfaces aux_util aux_math aux_tracking xrt-external-cjson)
list(APPEND ENABLED_HEADSET_DRIVERS wmr)
# Can only build camera support with libusb
if(XRT_HAVE_LIBUSB)
target_sources(drv_wmr PRIVATE wmr/wmr_camera.c)
target_include_directories(drv_wmr PUBLIC ${LIBUSB1_INCLUDE_DIRS})
target_link_libraries(drv_wmr PRIVATE ${LIBUSB1_LIBRARIES})
endif()
endif()
if(XRT_BUILD_SAMPLES)
# We build the sample driver to make sure it stays valid,
# but it never gets linked into a final target.
add_library(
drv_sample STATIC sample/sample_hmd.c sample/sample_interface.h
sample/sample_prober.c
)
target_link_libraries(drv_sample PRIVATE xrt-interfaces aux_util)
endif()
if(ENABLED_HEADSET_DRIVERS)
set(ENABLED_DRIVERS ${ENABLED_HEADSET_DRIVERS} ${ENABLED_DRIVERS})
list(SORT ENABLED_DRIVERS)
string(REPLACE ";" " " ENABLED_DRIVERS "${ENABLED_DRIVERS}")
message(STATUS "Enabled drivers: ${ENABLED_DRIVERS}")
else()
message(FATAL_ERROR "You must enable at least one headset driver to build Monado.")
endif()

由此可知,这边参与编译的有:

  • add_library(drv_dummy STATIC XXXX)
  • add_library(drv_remote STATIC XXXX)
  • add_library(drv_android STATIC XXXX)
  • add_library(drv_multi STATIC XXXX)
  • add_library(drv_wmr STATIC XXXX)
  • add_library(drv_sample STATIC XXXX)

变量ENABLED_HEADSET_DRIVERS,ENABLED_DRIVERS的值分别为

  • ENABLED_HEADSET_DRIVERS = dummy remote drv_multi wmr
  • ENABLED_DRIVERS = android

小结:这样的话也比较容易理解,整个drivers目录其实就是针对不同的driver模块做了实现,具体的需要到各个module中去看。

compositor

monado/src/xrt/compositor/CMakeLists.txt,compositor是整个monado runtime中比较重要的模块,拆解分析:

  • library : comp_client

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    # Copyright 2019-2021, Collabora, Ltd.
    # SPDX-License-Identifier: BSL-1.0
    ###
    # Client library
    #
    add_library(comp_client STATIC)
    target_link_libraries(
    comp_client
    PUBLIC xrt-interfaces
    PRIVATE aux_util
    )
    target_include_directories(comp_client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
  • link vulkan,XRT_HAVE_VULKAN:ON

    1
    2
    3
    4
    5
    6
    7
    if(XRT_HAVE_VULKAN)
    target_sources(
    comp_client PRIVATE client/comp_vk_client.c client/comp_vk_client.h
    client/comp_vk_glue.c
    )
    target_link_libraries(comp_client PRIVATE aux_vk)
    endif()
  • link open gles

    • XRT_HAVE_OPENGLES:ON
    • XRT_HAVE_OPENGL:OFF
    • XRT_HAVE_EGL:ON
    • XRT_HAVE_OPENGL_GLX:OFF
    • XRT_HAVE_XLIB:OFF
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    if(XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES)
    target_sources(
    comp_client
    PRIVATE client/comp_gl_client.c client/comp_gl_client.h
    client/comp_gl_memobj_swapchain.c client/comp_gl_memobj_swapchain.h
    )
    target_link_libraries(comp_client PRIVATE aux_ogl)
    endif()
    if(XRT_HAVE_OPENGL)
    target_sources(comp_client PRIVATE client/comp_gl_glue.c)
    endif()
    if(XRT_HAVE_OPENGLES)
    target_sources(comp_client PRIVATE client/comp_gles_glue.c)
    endif()
    if(XRT_HAVE_EGL)
    target_sources(
    comp_client PRIVATE client/comp_gl_eglimage_swapchain.c
    client/comp_gl_eglimage_swapchain.h
    )
    endif()
    if(XRT_HAVE_OPENGL_GLX AND XRT_HAVE_XLIB)
    target_sources(
    comp_client PRIVATE client/comp_gl_xlib_client.c client/comp_gl_xlib_client.h
    client/comp_gl_xlib_glue.c
    )
    target_link_libraries(comp_client PRIVATE OpenGL::GLX)
    endif()
    if(XRT_HAVE_EGL)
    target_sources(comp_client PRIVATE client/comp_egl_client.c client/comp_egl_client.h)
    endif()
  • util library ,XRT_HAVE_VULKAN:ON

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    ##
    # Util library
    #
    if(XRT_HAVE_VULKAN)
    add_library(
    comp_util STATIC
    util/comp_base.h
    util/comp_base.c
    util/comp_swapchain.h
    util/comp_swapchain.c
    util/comp_sync.h
    util/comp_sync.c
    util/comp_vulkan.h
    util/comp_vulkan.c
    )
    target_link_libraries(
    comp_util
    PUBLIC xrt-interfaces
    PRIVATE aux_util aux_os aux_vk
    )
    target_include_directories(comp_util PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
    endif()
  • Render library ,XRT_HAVE_VULKAN:ON

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    ##
    # Render library
    #
    if(XRT_HAVE_VULKAN)
    spirv_shaders(
    SHADER_HEADERS
    shaders/clear.comp
    shaders/distortion.comp
    shaders/distortion_timewarp.comp
    shaders/mesh.frag
    shaders/mesh.vert
    shaders/layer.frag
    shaders/layer.vert
    shaders/equirect1.vert
    shaders/equirect1.frag
    shaders/equirect2.vert
    shaders/equirect2.frag
    )
    add_library(
    comp_render STATIC
    ${SHADER_HEADERS}
    render/comp_buffer.c
    render/comp_compute.c
    render/comp_render.h
    render/comp_rendering.c
    render/comp_resources.c
    render/comp_shaders.c
    render/comp_util.c
    )
    target_link_libraries(
    comp_render
    PUBLIC xrt-interfaces
    PRIVATE aux_util aux_os aux_vk
    )
    target_include_directories(comp_render PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
    # Shaders - marked SYSTEM so we get no warnings
    target_include_directories(comp_render SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
    add_subdirectory(shaders)
    endif()
    • add_subdirectory(shaders)

      1
      2
      3
      4
      5
      # Copyright 2019, Collabora, Ltd.
      # SPDX-License-Identifier: BSL-1.0
      # CMakeLists.txt required for CMake to create the shaders/ directory in the build tree.
      # Generated shaders will be placed there.

      如注释所述,需要把整个shaders放在build tree中,因此只能放一个空的CMakeLists.txt

  • Main library,整个scope比较长,由于我们已经提前知晓:

    • XRT_FEATURE_COMPOSITOR_MAIN:OFF
    • XRT_HAVE_XCB:OFF
    • XRT_HAVE_XLIB:OFF
    • VK_USE_PLATFORM_ANDROID_KHR:ON
    • ANDROID:ON

    整个段落就被简化为:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    ##
    # Main library
    #
    if(XRT_FEATURE_COMPOSITOR_MAIN)
    add_library(
    comp_main STATIC
    main/comp_compositor.c
    main/comp_compositor.h
    main/comp_documentation.h
    main/comp_renderer.c
    main/comp_renderer.h
    main/comp_settings.c
    main/comp_settings.h
    main/comp_target.h
    main/comp_target_swapchain.c
    main/comp_target_swapchain.h
    main/comp_window.h
    main/comp_layer.h
    main/comp_layer.c
    main/comp_layer_renderer.h
    main/comp_layer_renderer.c
    )
    target_link_libraries(
    comp_main
    PUBLIC xrt-interfaces
    PRIVATE
    aux_util
    aux_os
    aux_vk
    comp_util
    comp_render
    )
    target_include_directories(comp_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
    if(ANDROID)
    target_sources(comp_main PRIVATE main/comp_window_android.c)
    target_link_libraries(comp_main PRIVATE aux_ogl aux_android)
    endif()
    endif()
  • 最后是multi client compositor library的部分:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    ###
    # Multi client compositor library
    #
    add_library(
    comp_multi STATIC multi/comp_multi_compositor.c multi/comp_multi_interface.h
    multi/comp_multi_private.h multi/comp_multi_system.c
    )
    target_link_libraries(
    comp_multi
    PUBLIC xrt-interfaces
    PRIVATE aux_util aux_os
    )
    target_include_directories(comp_multi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
    if(XRT_FEATURE_COMPOSITOR_MAIN)
    target_link_libraries(comp_main PRIVATE comp_multi)
    endif()

小结:整个compositor的构建目标是 comp_main

state_trackers

monado/src/xrt/state_trackers/CMakeLists.txt

本来的理解中,state_trackers是monado runtime的状态机切换中的tracker(待后续代码确认)。

先查看一下state_trackers/CMakeLists.txt,其中:

  • XRT_HAVE_OPENGL:OFF
  • XRT_FEATURE_STEAMVR_PLUGIN:OFF
1
2
3
4
5
6
7
8
9
10
11
12
# Copyright 2019, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
if(XRT_HAVE_OPENGL)
add_subdirectory(gui)
endif()
add_subdirectory(oxr)
add_subdirectory(prober)
if(XRT_FEATURE_STEAMVR_PLUGIN)
add_subdirectory(steamvr_drv)
endif()

因此整个就简化为两句话了:

1
2
add_subdirectory(oxr)
add_subdirectory(prober)

oxr

monado/src/xrt/state_trackers/oxr/CMakeLists.txt,另外我们通过根目录的CMakeLists.txt已知:

  • XRT_HAVE_VULKAN:ON
  • XRT_HAVE_OPENGL:OFF
  • XRT_HAVE_OPENGLES:ON
  • XRT_HAVE_XLIB:OFF
  • XRT_HAVE_EGL:ON
  • ANDROID:ON

整个CMakeLists.txt可以简化为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright 2019-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
###
# Main code
#
add_library(
st_oxr STATIC
oxr_api_action.c
oxr_api_funcs.h
oxr_api_instance.c
oxr_api_negotiate.c
oxr_api_session.c
oxr_api_space.c
oxr_api_swapchain.c
oxr_api_system.c
oxr_api_verify.h
oxr_binding.c
oxr_chain.h
oxr_event.c
oxr_extension_support.h
oxr_handle_base.c
oxr_input.c
oxr_input_transform.c
oxr_input_transform.h
oxr_instance.c
oxr_logger.c
oxr_logger.h
oxr_objects.h
oxr_path.c
oxr_session.c
oxr_session_frame_end.c
oxr_space.c
oxr_swapchain.c
oxr_system.c
oxr_two_call.h
oxr_verify.c
oxr_xdev.c
)
if(XRT_HAVE_VULKAN)
target_sources(st_oxr PRIVATE oxr_session_gfx_vk.c oxr_swapchain_vk.c oxr_vulkan.c)
target_link_libraries(st_oxr PUBLIC Vulkan::Vulkan)
endif()
if(XRT_HAVE_OPENGLES)
target_compile_definitions(st_oxr PRIVATE XR_USE_GRAPHICS_API_OPENGL_ES)
endif()
if(XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES)
target_sources(st_oxr PRIVATE oxr_session_gfx_gl.c oxr_swapchain_gl.c)
target_link_libraries(st_oxr PUBLIC aux_ogl)
endif()
if(ANDROID)
target_compile_definitions(st_oxr PRIVATE XR_USE_PLATFORM_ANDROID)
target_sources(st_oxr PRIVATE oxr_session_gfx_gles_android.c)
target_link_libraries(st_oxr PRIVATE aux_android)
endif()
target_link_libraries(
st_oxr
PRIVATE
xrt-interfaces
xrt-external-openxr
aux_util
aux_math
aux_generated_bindings
comp_client
aux-includes
PUBLIC aux_os
)
target_include_directories(
st_oxr
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..
)

因此整个target目标为:st_oxr

prober

monado/src/xrt/state_trackers/prober/CMakeLists.txt同样的,我们已知:

  • XRT_HAVE_LIBUDEV:OFF
  • XRT_HAVE_LIBUSB:OFF
  • XRT_HAVE_OPENCV:OFF
  • XRT_HAVE_V4L2:OFF
  • XRT_BUILD_DRIVER_REMOTE:ON

整个CMakeLists可以简化为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright 2019-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
add_library(
st_prober STATIC
p_documentation.h
p_dump.c
p_prober.c
p_prober.h
p_tracking.c
)
target_link_libraries(st_prober PUBLIC xrt-interfaces)
target_link_libraries(
st_prober
PRIVATE
drv_includes
drv_multi
aux_util
aux_os
aux_tracking
)
if(XRT_BUILD_DRIVER_REMOTE)
target_link_libraries(st_prober PRIVATE drv_remote)
endif()

因此整个target目标为:st_prober

小结:对于state_trackers来说,最终会出现两个target:st_oxr以及st_prober

targets

monado/src/xrt/targets/CMakeLists.txt

targets在gradle的编译中其实已经有提到了,我们起点的部分是在openxr_android,最终绕了一圈又回到了这里。

一样的分析流程:

  • XRT_FEATURE_OPENXR:ON
  • XRT_HAVE_SDL2:OFF
  • XRT_FEATURE_SERVICE:OFF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copyright 2019-2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
######
# This is where we collect all of the pieces from the different parts of
# the source tree and build a complete driver or integration part.
add_subdirectory(common)
if(XRT_FEATURE_OPENXR)
add_subdirectory(openxr)
endif()
add_subdirectory(cli)

common

monado/src/xrt/targets/common/CMakeLists.txt

继续分析

  • XRT_BUILD_DRIVER_ARDUINO
  • XRT_BUILD_DRIVER_DAYDREAM
  • XRT_BUILD_DRIVER_DEPTHAI
  • XRT_BUILD_DRIVER_QWERTY
  • XRT_BUILD_DRIVER_HDK
  • XRT_BUILD_DRIVER_HYDRA
  • XRT_BUILD_DRIVER_NS
  • XRT_BUILD_DRIVER_ULV2
  • XRT_BUILD_DRIVER_OHMD
  • XRT_BUILD_DRIVER_PSMV
  • XRT_BUILD_DRIVER_PSVR
  • XRT_BUILD_DRIVER_REALSENSE
  • XRT_BUILD_DRIVER_VIVE
  • XRT_BUILD_DRIVER_VF
  • XRT_BUILD_DRIVER_HANDTRACKING
  • XRT_BUILD_DRIVER_SURVIVE
  • XRT_BUILD_DRIVER_ILLIXR
  • XRT_BUILD_DRIVER_EUROC

整个CMakeLists就会被简化为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright 2019-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
####
# Lists
#
add_library(target_lists STATIC target_lists.c)
target_link_libraries(
target_lists
PRIVATE
xrt-interfaces
aux_util # TODO Remove this after removing #include "util/u_time.h" from xrt_defines.h
drv_includes
)
target_include_directories(target_lists PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(XRT_BUILD_DRIVER_DUMMY)
target_link_libraries(target_lists PRIVATE drv_dummy)
endif()
if(XRT_BUILD_DRIVER_REMOTE)
target_link_libraries(target_lists PRIVATE drv_remote)
endif()
if(XRT_HAVE_V4L2)
target_link_libraries(target_lists PRIVATE drv_v4l2)
endif()
if(XRT_BUILD_DRIVER_ANDROID)
target_link_libraries(target_lists PRIVATE drv_android)
endif()
if(XRT_BUILD_DRIVER_WMR)
target_link_libraries(target_lists PRIVATE drv_wmr)
endif()
####
# Instance
#
if(XRT_FEATURE_COMPOSITOR_MAIN)
add_library(target_instance STATIC target_instance.c)
target_link_libraries(
target_instance
PRIVATE
xrt-interfaces
aux_util
st_prober
target_lists
comp_main
drv_includes
)
target_include_directories(target_instance PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
endif()
####
# Instance without Compositor
#
add_library(target_instance_no_comp STATIC target_instance_no_comp.c)
target_link_libraries(
target_instance_no_comp
PRIVATE
xrt-interfaces
aux_util
st_prober
target_lists
drv_includes
)
target_include_directories(target_instance_no_comp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

最终这边会出现的target为:

  • target_lists
  • target_instance
  • target_instance_no_comp

openxr

monado/src/xrt/targets/openxr/CMakeLists.txt,同样的,我们把预先定义的宏都展开

  • XRT_FEATURE_SERVICE:OFF,因为使用的是inProcess模式
  • MSVC:OFF,因为没有使用microsoft visual c++编译器
  • RUNTIME_BARE_SUFFIX = monado,RUNTIME_PREFIX = "",因此RUNTIME_TARGET = openxr_monado
  • XRT_HAVE_OPENGL:OFF
  • CMAKE_SYSTEM_NAME:Android
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Copyright 2019, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
######
# Create a loadable OpenXR driver.
set(RUNTIME_BARE_SUFFIX monado)
set(RUNTIME_SUFFIX _${RUNTIME_BARE_SUFFIX})
set(RUNTIME_TARGET
${RUNTIME_PREFIX}openxr${RUNTIME_SUFFIX}
CACHE INTERNAL "" FORCE
)
# OpenXR 1.0
set(XR_API_MAJOR "1")
add_library(${RUNTIME_TARGET} MODULE target.c libopenxr.def)
# Note: Order may matter in these lists!
target_link_libraries(${RUNTIME_TARGET} PUBLIC aux_vk aux_os aux_util aux_math)
if(XRT_FEATURE_SERVICE)
target_link_libraries(${RUNTIME_TARGET} PUBLIC st_oxr ipc_client comp_client)
else()
target_link_libraries(
${RUNTIME_TARGET}
PUBLIC
st_oxr
st_prober
target_lists
target_instance
comp_main
comp_client
)
endif()
if(NOT MSVC)
# Force the main "negotiate" symbol's inclusion
# and use a version script to ensure that's the only one we expose.
set_property(
TARGET ${RUNTIME_TARGET}
APPEND_STRING
PROPERTY
LINK_FLAGS
"-u xrNegotiateLoaderRuntimeInterface -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libopenxr.version"
)
# Re-link if the version script changes.
set_property(
TARGET ${RUNTIME_TARGET}
APPEND
PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libopenxr.version"
)
endif()
# Install the runtime itself
install(
TARGETS ${RUNTIME_TARGET} #
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} #
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} #
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
###
# Generate runtime manifest with absolute path to runtime intended for development without installing
set(MANIFEST_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/openxr_monado.in.json)
set(runtime_path $<TARGET_FILE:${RUNTIME_TARGET}>)
# Need this step because file(GENERATE) only evaluates generator expressions, and not what configure_file does.
configure_file(${MANIFEST_INPUT} ${CMAKE_CURRENT_BINARY_DIR}/intermediate_manifest.json)
if(CMAKE_VERSION VERSION_LESS 3.9)
# best guess
if(CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(IS_MULTI_CONFIG FALSE)
else()
set(IS_MULTI_CONFIG TRUE)
endif()
else()
# 3.9+ have a global property with the truth
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
endif()
if(IS_MULTI_CONFIG)
set(DEV_MANIFEST_OUTPUT "${CMAKE_BINARY_DIR}/$<CONFIG>/${RUNTIME_TARGET}-dev.json")
else()
set(DEV_MANIFEST_OUTPUT "${CMAKE_BINARY_DIR}/${RUNTIME_TARGET}-dev.json")
endif()
file(
GENERATE
OUTPUT "${DEV_MANIFEST_OUTPUT}"
INPUT ${CMAKE_CURRENT_BINARY_DIR}/intermediate_manifest.json
)
###
# Prepare the installable manifest: will be generated completely at install time,
# by a script we generate now.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(MANIFEST_RELATIVE_DIR share/openxr/${XR_API_MAJOR}/)
if(XRT_OPENXR_INSTALL_ACTIVE_RUNTIME)
configure_file(
active_runtime.cmake ${CMAKE_CURRENT_BINARY_DIR}/active_runtime.cmake @ONLY
)
install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/active_runtime.cmake)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# TODO: install target on windows just needs to know where to install manifest
set(MANIFEST_RELATIVE_DIR)
endif()
# If we know where to install the manifest, we can set it up to be installed.
if(MANIFEST_RELATIVE_DIR)
set(RUNTIME_RELATIVE_DIR ${CMAKE_INSTALL_LIBDIR})
set(RUNTIME_FILENAME
${CMAKE_SHARED_MODULE_PREFIX}${RUNTIME_TARGET}${CMAKE_SHARED_MODULE_SUFFIX}
)
configure_file(make_manifest.cmake ${CMAKE_CURRENT_BINARY_DIR}/make_manifest.cmake @ONLY)
install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/make_manifest.cmake)
endif()
###
# Inelegant but effective SDL2-based debug GUI
add_library(oxr_sdl2 STATIC oxr_sdl2_hack.c)
target_link_libraries(oxr_sdl2 PRIVATE aux_util)
if(XRT_HAVE_OPENGL)
target_link_libraries(oxr_sdl2 PUBLIC aux_ogl)
endif()
if(XRT_HAVE_SDL2)
target_link_libraries(oxr_sdl2 PRIVATE st_gui xrt-external-imgui-sdl2 ${SDL2_LIBRARIES})
if(XRT_BUILD_DRIVER_QWERTY)
target_link_libraries(oxr_sdl2 PRIVATE drv_qwerty drv_qwerty_includes)
endif()
endif()
target_link_libraries(${RUNTIME_TARGET} PRIVATE oxr_sdl2)
  • 切记:add_library(${RUNTIME_TARGET} MODULE target.c libopenxr.def)

  • targets/openxr定义了一个openxr_monado的target,这个部分跟build.gradle的部分联系了起来,在android gradle项目中的最终target就是openxr_monado

    1
    2
    3
    4
    5
    6
    7
    8
    9
    productFlavors {
    inProcess {
    dimension 'deployment'
    applicationIdSuffix '.in_process'
    externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=OFF"
    externalNativeBuild.cmake.targets "openxr_monado"
    resValue "string", "app_name", "Monado XR"
    }

cil

monado/src/xrt/targets/cil/CMakeLists.txt

cil = Common Intermediate Language,这个模块可以认为是一种用来调试的辅助工具,类似android中am,wm命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright 2019-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
######
# Create a cli interface for Monado.
add_executable(
cli
cli_cmd_lighthouse.c
cli_cmd_probe.c
cli_cmd_test.c
cli_common.h
cli_main.c
)
add_sanitizers(cli)
if(NOT WIN32)
# No getline on Windows, so until we have a portable impl
target_sources(cli PRIVATE cli_cmd_calibrate.c)
endif()
set_target_properties(cli PROPERTIES OUTPUT_NAME monado-cli PREFIX "")
target_link_libraries(cli PRIVATE aux_os aux_util aux_math target_instance_no_comp)
install(TARGETS cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

ipc

monado/src/xrt/ipc/CMakeLists.txt,ipc的部分顾名思义,应该是进程间通讯会用到的模块,理论上来说应该是outProcess下会用到的部分。

  • XRT_HAVE_SYSTEMD:OFF
  • RT_LIBRARY:OFF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright 2020-2021, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
###
# Generator
foreach(
fn
ipc_protocol_generated.h
ipc_client_generated.h
ipc_client_generated.c
ipc_server_generated.h
ipc_server_generated.c
)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${fn}"
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/shared/proto.py
${CMAKE_CURRENT_SOURCE_DIR}/shared/proto.json
"${CMAKE_CURRENT_BINARY_DIR}/${fn}"
VERBATIM
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/shared/proto.py
${CMAKE_CURRENT_SOURCE_DIR}/shared/ipcproto/common.py
${CMAKE_CURRENT_SOURCE_DIR}/shared/proto.json
COMMENT "Generating ${fn} from protocol JSON description"
)
endforeach()
set(IPC_COMMON_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/ipc_protocol_generated.h
shared/ipc_shmem.c
shared/ipc_shmem.h
shared/ipc_utils.c
shared/ipc_utils.h
)
add_library(ipc_shared STATIC ${IPC_COMMON_SOURCES})
target_include_directories(
ipc_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(ipc_shared PRIVATE aux_util)
if(RT_LIBRARY)
target_link_libraries(ipc_shared PUBLIC ${RT_LIBRARY})
endif()
###
# Client
add_library(
ipc_client STATIC
${CMAKE_CURRENT_BINARY_DIR}/ipc_client_generated.c
${CMAKE_CURRENT_BINARY_DIR}/ipc_client_generated.h
client/ipc_client.h
client/ipc_client_compositor.c
client/ipc_client_device.c
client/ipc_client_hmd.c
client/ipc_client_instance.c
)
target_include_directories(
ipc_client PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(ipc_client PRIVATE aux_util ipc_shared)
###
# Server
add_library(
ipc_server STATIC
${CMAKE_CURRENT_BINARY_DIR}/ipc_server_generated.c
${CMAKE_CURRENT_BINARY_DIR}/ipc_server_generated.h
server/ipc_server.h
server/ipc_server_handler.c
server/ipc_server_per_client_thread.c
server/ipc_server_process.c
)
target_include_directories(
ipc_server
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(ipc_server PRIVATE aux_util ipc_shared)
if(XRT_HAVE_SYSTEMD)
target_include_directories(ipc_server PRIVATE ${SYSTEMD_INCLUDE_DIRS})
target_link_libraries(ipc_server PRIVATE ${SYSTEMD_LIBRARIES})
endif()
if(ANDROID)
add_library(
ipc_android STATIC
android/ipc_client_android.cpp
android/ipc_client_android.h
android/org.freedesktop.monado.ipc.cpp
android/org.freedesktop.monado.ipc.hpp
android/org.freedesktop.monado.ipc.impl.hpp
)
target_link_libraries(
ipc_android PUBLIC xrt-external-jni-wrap xrt-external-jnipp aux_android
)
target_sources(
ipc_server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/server/ipc_server_mainloop_android.c
)
target_link_libraries(
ipc_shared
PUBLIC ${ANDROID_LIBRARY}
PRIVATE aux_android ipc_android
)
elseif(XRT_HAVE_LINUX)
target_sources(
ipc_server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/server/ipc_server_mainloop_linux.c
)
endif()

这边所有的target为:

  • ipc_shared
  • ipc_client
  • ipc_server
  • ipc_android

Target link

根据之前对整个CMakeLists的阅读,我们可以厘清整个targe的link链,但是我们需要的link是哪个?这个就需要回到build.gradle里去了。

还记得monado/src/xrt/targets/openxr_android/build.gradle吗?其中对于inProcessoutProcess

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
plugins {
id 'com.android.application'
......
}
......
android {
......
defaultConfig {
applicationId 'org.freedesktop.monado.openxr_runtime'
......
}
......
externalNativeBuild {
cmake {
path "${rootDir}/CMakeLists.txt"
}
}
......
flavorDimensions 'deployment'
productFlavors {
inProcess {
dimension 'deployment'
applicationIdSuffix '.in_process'
externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=OFF"
externalNativeBuild.cmake.targets "openxr_monado"
resValue "string", "app_name", "Monado XR"
}
outOfProcess {
dimension 'deployment'
applicationIdSuffix '.out_of_process'
externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=ON"
externalNativeBuild.cmake.targets "openxr_monado", "monado-service"
resValue "string", "app_name", "Monado XR (Out-of-Proc)"
}
}
......
}
......
dependencies {
......
}

target:openxr_monado

build.gradle中针对inProcess的flavor,我们可以看到CMakeLists的交付件为:openxr_monado,我们根据之前的link list来反溯一下需要用到哪些模块。

首先是整个target的入口monado/src/xrt/targets/openxr/CMakeLists.txtadd_library(${RUNTIME_TARGET} MODULE target.c libopenxr.def)

add_library(openxr_monado MODULE target.c libopenxr.def)

其中的link依赖如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
target_link_libraries(${RUNTIME_TARGET} PUBLIC aux_vk aux_os aux_util aux_math)
target_link_libraries(
${RUNTIME_TARGET}
PUBLIC
st_oxr
st_prober
target_lists
target_instance
comp_main
comp_client
)
target_link_libraries(${RUNTIME_TARGET} PRIVATE oxr_sdl2)
  • 因此target:openxr_monado依赖路径:aux_vk,aux_os,aux_util,aux_math,st_oxr,st_prober,target_lists,target_instance,comp_main,comp_client,oxr_sdl2

      graph TD
    openxr_monado --> st_oxr
    openxr_monado --> st_prober
    openxr_monado --> target_lists
    openxr_monado --> target_instance
    openxr_monado --> comp_main
    openxr_monado --> comp_client
    openxr_monado --> aux_vk 
    openxr_monado --> aux_os 
    openxr_monado --> aux_util 
    openxr_monado --> aux_math

依赖关系

我们挨个展开来看一下每个库的依赖关系

aux_vk

aux_vk:aux_os,aux_util,Vulkan::Vulkan,aux_android,android

graph TD
aux_vk --> aux_os
aux_vk --> aux_util
aux_vk --> Vulkan::Vulkan
aux_vk --> aux_android
aux_vk --> android

aux_os

aux_os:aux-includes,xrt-pthreads

graph TD
aux_os --> aux-includes
aux_os --> xrt-pthreads

aux_util

aux_util:aux-includes,xrt-pthreads,aux_generated_bindings,aux_math,${JPEG_LIBRARIES},xrt-external-cjson,${ANDROID_LOG_LIBRARY}

graph TD
aux_util --> aux-includes
aux_util --> xrt-pthreads
aux_util --> aux_generated_bindings
aux_util --> aux_math
aux_util --> JPEG_LIBRARIES
aux_util --> xrt-external-cjson
aux_util --> ANDROID_LOG_LIBRARY

aux_math

aux_math:aux-includes,aux_util

graph TD
aux_math --> aux-includes
aux_math --> aux_util

st_oxr

st_oxr:Vulkan::Vulkan,aux_ogl,aux_android

graph TD
st_oxr --> Vulkan::Vulkan
st_oxr --> aux_ogl
st_oxr --> aux_android

st_prober

st_prober:xrt-interfaces,drv_remote,drv_includes,drv_multi,aux_util,aux_os,aux_tracking

graph TD
st_prober --> xrt-interfaces
st_prober --> drv_remote
st_prober --> drv_includes
st_prober --> drv_multi
st_prober --> aux_util
st_prober --> aux_os
st_prober --> aux_tracking

target_lists

target_lists:xrt-interfaces,aux_util,drv_includes,drv_dummy,drv_remote,drv_android,drv_multi,drv_wmr

graph TD
target_lists --> xrt-interfaces
target_lists --> aux_util
target_lists --> drv_includes
target_lists --> drv_dummy
target_lists --> drv_remote
target_lists --> drv_android
target_lists --> drv_multi
target_lists --> drv_wmr

target_instance

target_instance:xrt-interfaces,aux_util,st_prober,target_lists,comp_main,drv_includes

graph TD
target_instance --> xrt-interfaces
target_instance --> aux_util
target_instance --> st_prober
target_instance --> target_lists
target_instance --> comp_main
target_instance --> drv_includes

comp_main

comp_main:xrt-interfaces,aux_util,aux_os,aux_vk,comp_util,comp_render,aux_ogl,aux_android,comp_multi

graph TD
comp_main --> xrt-interfaces
comp_main --> aux_util
comp_main --> aux_os
comp_main --> aux_vk
comp_main --> comp_util
comp_main --> comp_render
comp_main --> aux_ogl
comp_main --> aux_android
comp_main --> comp_multi

comp_client

comp_client:xrt-interfaces,aux_util,aux_vk,aux_ogl

graph TD
comp_client --> xrt-interfaces
comp_client --> aux_util
comp_client --> aux_vk
comp_client --> aux_ogl

oxr_sdl2

oxr_sdl2:aux_util,aux_ogl

graph TD
oxr_sdl2 --> aux_util
oxr_sdl2 --> aux_ogl

二级依赖

aux_generated_bindings

aux_generated_bindings:xrt-interfaces,aux_util

graph TD
aux_generated_bindings --> xrt-interfaces
aux_generated_bindings --> aux_util

comp_util

comp_util:xrt-interfaces,aux_util,aux_os,aux_vk

graph TD
comp_util --> xrt-interfaces
comp_util --> aux_util
comp_util --> aux_os
comp_util --> aux_vk

aux_ogl

aux_ogl:aux-includes,xrt-external-glad,EGL::EGL

graph TD
aux_ogl --> aux-includes
aux_ogl --> xrt-external-glad
aux_ogl --> EGL::EGL

aux_android

aux_android:aux_util,${ANDROID_LIBRARY},${ANDROID_LOG_LIBRARY},xrt-external-jni-wrap,xrt-external-jnipp,android_app_glue

graph TD
aux_android --> aux_util
aux_android --> ANDROID_LIBRARY
aux_android --> ANDROID_LOG_LIBRARY
aux_android --> xrt-external-jni-wrap
aux_android --> xrt-external-jnipp
aux_android --> android_app_glue

comp_multi

comp_multi:xrt-interfaces,aux_util,aux_os

graph TD
comp_multi --> xrt-interfaces
comp_multi --> aux_util
comp_multi --> aux_os

aux_tracking

aux_tracking:aux-includes,xrt-external-cjson,aux_math,aux_util,xrt-external-flexkalman,xrt-external-hungarian

graph TD
aux_tracking --> aux-includes
aux_tracking --> xrt-external-cjson
aux_tracking --> aux_math
aux_tracking --> aux_util
aux_tracking --> xrt-external-flexkalman
aux_tracking --> xrt-external-hungarian

drv_multi

drv_multi:xrt-interfaces,aux_util

graph TD
drv_multi --> xrt-interfaces
drv_multi --> aux_util

drv_remote

drv_remote:xrt-interfaces,aux_util

graph TD
drv_remote --> xrt-interfaces
drv_remote --> aux_util

drv_android

drv_android:xrt-interfaces,aux_util,aux_os,aux_android,${ANDROID_LIBRARY}

graph TD
drv_android --> xrt-interfaces
drv_android --> aux_util
drv_android --> aux_os
drv_android --> aux_android
drv_android --> ANDROID_LIBRARY

drv_wmr

drv_wmr:xrt-interfaces,aux_util,aux_math,aux_tracking,xrt-external-cjson

graph TD
drv_wmr --> xrt-interfaces
drv_wmr --> aux_util
drv_wmr --> aux_math
drv_wmr --> aux_tracking
drv_wmr --> xrt-external-cjson

comp_render

comp_render:aux_util,aux_os,aux_vk

graph TD
comp_render --> aux_util
comp_render --> aux_os
comp_render --> aux_vk

整体结构

这个时候通过展开这样的一个拓扑关系树,我们就可以得到整个openxr_monado的编译依赖了。

flowchart LR

openxr_monado --> st_oxr
openxr_monado --> st_prober
openxr_monado --> target_lists
openxr_monado --> target_instance
openxr_monado --> comp_main
openxr_monado --> comp_client
openxr_monado --> aux_vk 
openxr_monado --> aux_os 
openxr_monado --> aux_util 
openxr_monado --> aux_math
aux_vk --> aux_os
aux_vk --> aux_util
aux_vk --> Vulkan::Vulkan
aux_vk --> aux_android
aux_vk --> android
aux_os --> aux-includes
aux_os --> xrt-pthreads
aux_util --> aux-includes
aux_util --> xrt-pthreads
aux_util --> aux_generated_bindings
aux_util --> aux_math
aux_util --> JPEG_LIBRARIES
aux_util --> xrt-external-cjson
aux_util --> ANDROID_LOG_LIBRARY 
aux_math --> aux-includes
aux_math --> aux_util
st_oxr --> Vulkan::Vulkan
st_oxr --> aux_ogl
st_oxr --> aux_android
st_prober --> xrt-interfaces
st_prober --> drv_remote
st_prober --> drv_includes
st_prober --> drv_multi
st_prober --> aux_util
st_prober --> aux_os
st_prober --> aux_tracking
target_lists --> xrt-interfaces
target_lists --> aux_util
target_lists --> drv_includes
target_lists --> drv_dummy
target_lists --> drv_remote
target_lists --> drv_android
target_lists --> drv_multi
target_lists --> drv_wmr
target_instance --> xrt-interfaces
target_instance --> aux_util
target_instance --> st_prober
target_instance --> target_lists
target_instance --> comp_main
target_instance --> drv_includes
comp_main --> xrt-interfaces
comp_main --> aux_util
comp_main --> aux_os
comp_main --> aux_vk
comp_main --> comp_util
comp_main --> comp_render
comp_main --> aux_ogl
comp_main --> aux_android
comp_main --> comp_multi
comp_client --> xrt-interfaces
comp_client --> aux_util
comp_client --> aux_vk
comp_client --> aux_ogl
oxr_sdl2 --> aux_util
oxr_sdl2 --> aux_ogl
aux_generated_bindings --> xrt-interfaces
aux_generated_bindings --> aux_util
comp_util --> xrt-interfaces
comp_util --> aux_util
comp_util --> aux_os
comp_util --> aux_vk
aux_ogl --> aux-includes
aux_ogl --> xrt-external-glad
aux_ogl --> EGL::EGL
aux_android --> aux_util
aux_android --> ANDROID_LIBRARY
aux_android --> ANDROID_LOG_LIBRARY
aux_android --> xrt-external-jni-wrap
aux_android --> xrt-external-jnipp
aux_android --> android_app_glue
comp_multi --> xrt-interfaces
comp_multi --> aux_util
comp_multi --> aux_os
aux_tracking --> aux-includes
aux_tracking --> xrt-external-cjson
aux_tracking --> aux_math
aux_tracking --> aux_util
aux_tracking --> xrt-external-flexkalman
aux_tracking --> xrt-external-hungarian
drv_multi --> xrt-interfaces
drv_multi --> aux_util
drv_remote --> xrt-interfaces
drv_remote --> aux_util
drv_android --> xrt-interfaces
drv_android --> aux_util
drv_android --> aux_os
drv_android --> aux_android
drv_android --> ANDROID_LIBRARY
drv_wmr --> xrt-interfaces
drv_wmr --> aux_util
drv_wmr --> aux_math
drv_wmr --> aux_tracking
drv_wmr --> xrt-external-cjson
comp_render --> aux_util
comp_render --> aux_os
comp_render --> aux_vk

总结

  • 整个Android相关的工程编译是从monado/src/xrt/targets/openxr_android/build.gralde开始的

  • Android工程在Native端的build target:openxr_monado,交付件:libopenxr_monado.so,该target定义在:monado/src/xrt/targets/openxr/CMakeLists.txt

  • 编译过程中某些config开关可以直接去查看CMakeCache文件,以arm64-v8a为例,中间文件在如下地址:

    • monado/src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/arm64-v8a/CMakeCache.txt

  • 跟graphic相关的库有aux_vkaux_ogl,这一部分的定义在:monado/src/xrt/auxiliary/CMakeLists.txt

    • 代码部分在:monado/src/xrt/auxiliary/oglmonado/src/xrt/auxiliary/vk
  • 跟android相关部分aux_android,这一部分的定义在:monado/src/xrt/auxiliary/CMakeLists.txt

    • 代码的部分在:monado/src/xrt/auxiliary/android
  • 支持的设备是在target_lists,这个部分需要再去看代码确认一下仅仅是驱动,还是类似hal的中间层

    • 其中drv_androidmonado/src/xrt/drivers/android/下的文件编译而成,其中包含android_sensor.c,主要是做了g sensor数据的获取,以及3dof算法
  • comp_xxx的部分应该是重中之中,其中牵扯到不少都是VR核心的渲染部分?这个需要后续深入去看

    • compositor的流程是什么,大致的框架
    • comp_clientcomp_main,comp_multi之间是什么关系
  • 最终是关于opengles和vulkan的,这个部分的重点应该是落在实现上,而不是应用上,所以后续需要理解的是各个命令的具体实现,GPU到底做了什么。